package com.cheng.controller;

import com.cheng.pojo.AppCategory;
import com.cheng.pojo.AppInfo;
import com.cheng.pojo.DataDictionary;
import com.cheng.service.appcategory.AppCategoryService;
import com.cheng.service.appinfo.AppInfoService;
import com.cheng.service.datadictionary.DataDictionaryService;
import com.cheng.utils.PageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@SuppressWarnings("all")
@RequestMapping(value = "/appcate")
public class AppCategoryController {
    @Autowired
    private DataDictionaryService dataDictionaryService;
    @Autowired
    private AppCategoryService appCategoryService;
    @Autowired
    private AppInfoService appInfoService;

    @RequestMapping(value = "/applist")
    public String appList(Model model) {
        List<DataDictionary> flatform = dataDictionaryService.getAllFlatform();
        model.addAttribute("flatform", flatform);

        PageUtils pageUtils = new PageUtils();
        pageUtils.setCurrentPage(1);
        pageUtils.setPageSize(5);

        AppInfo appInfo = new AppInfo();
        appInfo.setSoftwareName("");
        appInfoService.findAll(appInfo, pageUtils);
        model.addAttribute("page", pageUtils);

        List<AppCategory> typeLevel1 = appCategoryService.getTypeLevel1();
        model.addAttribute("typeLevel1", typeLevel1);
        return "backend/applist";
    }

    @RequestMapping(value = "/typeLevel2")
    @ResponseBody
    public List<AppCategory> typeLevel2(Integer pid) {
        List<AppCategory> typeLevel2 = appCategoryService.getTypeLevel2(pid);
        return typeLevel2;
    }

    @RequestMapping(value = "/typeLevel3")
    @ResponseBody
    public List<AppCategory> typeLevel3(Integer pid) {
        List<AppCategory> typeLevel3 = appCategoryService.getTypeLevel3(pid);
        return typeLevel3;
    }

    @RequestMapping(value = "/typeLevel1")
    @ResponseBody
    public List<AppCategory> typeLevel1() {
        List<AppCategory> typeLevel1 = appCategoryService.getTypeLevel1();
        return typeLevel1;
    }
}
